﻿using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using ChinaSoft.DBUtility;//Please add references
namespace ChinaSoft.DAL
{
	/// <summary>
	/// 数据访问类:DAL_T_PET_OWENER
	/// </summary>
	public partial class DAL_T_PET_OWENER
	{
		public DAL_T_PET_OWENER()
		{}
		#region  Method

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string PET_OWENER_ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from T_PET_OWENER");
			strSql.Append(" where PET_OWENER_ID=:PET_OWENER_ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":PET_OWENER_ID", OracleType.VarChar,40)			};
			parameters[0].Value = PET_OWENER_ID;

			return DbHelperOra.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(ChinaSoft.Model.Model_T_PET_OWENER model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into T_PET_OWENER(");
			strSql.Append("PET_OWENER_ID,ADDRESS,BIRTHDAY,CARD_ID,CARD_TYPE,EMAIL,MOBILE,NOTE,ORG_NAME,PER_NAME,PHONE,POST_NUM,REG_ORG_ID,SEX,IS_SMS,STATE,TYPE,IS_EMAIL,IS_MAIL,CREATE_TIME,CREATOR_ID,UPDATE_TIME,UPDATOR_ID)");
			strSql.Append(" values (");
			strSql.Append(":PET_OWENER_ID,:ADDRESS,:BIRTHDAY,:CARD_ID,:CARD_TYPE,:EMAIL,:MOBILE,:NOTE,:ORG_NAME,:PER_NAME,:PHONE,:POST_NUM,:REG_ORG_ID,:SEX,:IS_SMS,:STATE,:TYPE,:IS_EMAIL,:IS_MAIL,:CREATE_TIME,:CREATOR_ID,:UPDATE_TIME,:UPDATOR_ID)");
			OracleParameter[] parameters = {
					new OracleParameter(":PET_OWENER_ID", OracleType.VarChar,40),
					new OracleParameter(":ADDRESS", OracleType.NVarChar),
					new OracleParameter(":BIRTHDAY", OracleType.DateTime),
					new OracleParameter(":CARD_ID", OracleType.NVarChar),
					new OracleParameter(":CARD_TYPE", OracleType.Number,10),
					new OracleParameter(":EMAIL", OracleType.NVarChar),
					new OracleParameter(":MOBILE", OracleType.NVarChar),
					new OracleParameter(":NOTE", OracleType.NVarChar),
					new OracleParameter(":ORG_NAME", OracleType.NVarChar),
					new OracleParameter(":PER_NAME", OracleType.NVarChar),
					new OracleParameter(":PHONE", OracleType.NVarChar),
					new OracleParameter(":POST_NUM", OracleType.NVarChar),
					new OracleParameter(":REG_ORG_ID", OracleType.VarChar,40),
					new OracleParameter(":SEX", OracleType.NVarChar),
					new OracleParameter(":IS_SMS", OracleType.NVarChar),
					new OracleParameter(":STATE", OracleType.NVarChar),
					new OracleParameter(":TYPE", OracleType.Number,10),
					new OracleParameter(":IS_EMAIL", OracleType.NVarChar),
					new OracleParameter(":IS_MAIL", OracleType.NVarChar),
					new OracleParameter(":CREATE_TIME", OracleType.DateTime),
					new OracleParameter(":CREATOR_ID", OracleType.VarChar,40),
					new OracleParameter(":UPDATE_TIME", OracleType.DateTime),
					new OracleParameter(":UPDATOR_ID", OracleType.VarChar,40)};
			parameters[0].Value = model.PET_OWENER_ID;
			parameters[1].Value = model.ADDRESS;
			parameters[2].Value = model.BIRTHDAY;
			parameters[3].Value = model.CARD_ID;
			parameters[4].Value = model.CARD_TYPE;
			parameters[5].Value = model.EMAIL;
			parameters[6].Value = model.MOBILE;
			parameters[7].Value = model.NOTE;
			parameters[8].Value = model.ORG_NAME;
			parameters[9].Value = model.PER_NAME;
			parameters[10].Value = model.PHONE;
			parameters[11].Value = model.POST_NUM;
			parameters[12].Value = model.REG_ORG_ID;
			parameters[13].Value = model.SEX;
			parameters[14].Value = model.IS_SMS;
			parameters[15].Value = model.STATE;
			parameters[16].Value = model.TYPE;
			parameters[17].Value = model.IS_EMAIL;
			parameters[18].Value = model.IS_MAIL;
			parameters[19].Value = model.CREATE_TIME;
			parameters[20].Value = model.CREATOR_ID;
			parameters[21].Value = model.UPDATE_TIME;
			parameters[22].Value = model.UPDATOR_ID;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(ChinaSoft.Model.Model_T_PET_OWENER model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update T_PET_OWENER set ");
			strSql.Append("ADDRESS=:ADDRESS,");
			strSql.Append("BIRTHDAY=:BIRTHDAY,");
			strSql.Append("CARD_ID=:CARD_ID,");
			strSql.Append("CARD_TYPE=:CARD_TYPE,");
			strSql.Append("EMAIL=:EMAIL,");
			strSql.Append("MOBILE=:MOBILE,");
			strSql.Append("NOTE=:NOTE,");
			strSql.Append("ORG_NAME=:ORG_NAME,");
			strSql.Append("PER_NAME=:PER_NAME,");
			strSql.Append("PHONE=:PHONE,");
			strSql.Append("POST_NUM=:POST_NUM,");
			strSql.Append("REG_ORG_ID=:REG_ORG_ID,");
			strSql.Append("SEX=:SEX,");
			strSql.Append("IS_SMS=:IS_SMS,");
			strSql.Append("STATE=:STATE,");
			strSql.Append("TYPE=:TYPE,");
			strSql.Append("IS_EMAIL=:IS_EMAIL,");
			strSql.Append("IS_MAIL=:IS_MAIL,");
			strSql.Append("CREATE_TIME=:CREATE_TIME,");
			strSql.Append("CREATOR_ID=:CREATOR_ID,");
			strSql.Append("UPDATE_TIME=:UPDATE_TIME,");
			strSql.Append("UPDATOR_ID=:UPDATOR_ID");
			strSql.Append(" where PET_OWENER_ID=:PET_OWENER_ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":ADDRESS", OracleType.NVarChar),
					new OracleParameter(":BIRTHDAY", OracleType.DateTime),
					new OracleParameter(":CARD_ID", OracleType.NVarChar),
					new OracleParameter(":CARD_TYPE", OracleType.Number,10),
					new OracleParameter(":EMAIL", OracleType.NVarChar),
					new OracleParameter(":MOBILE", OracleType.NVarChar),
					new OracleParameter(":NOTE", OracleType.NVarChar),
					new OracleParameter(":ORG_NAME", OracleType.NVarChar),
					new OracleParameter(":PER_NAME", OracleType.NVarChar),
					new OracleParameter(":PHONE", OracleType.NVarChar),
					new OracleParameter(":POST_NUM", OracleType.NVarChar),
					new OracleParameter(":REG_ORG_ID", OracleType.VarChar,40),
					new OracleParameter(":SEX", OracleType.NVarChar),
					new OracleParameter(":IS_SMS", OracleType.NVarChar),
					new OracleParameter(":STATE", OracleType.NVarChar),
					new OracleParameter(":TYPE", OracleType.Number,10),
					new OracleParameter(":IS_EMAIL", OracleType.NVarChar),
					new OracleParameter(":IS_MAIL", OracleType.NVarChar),
					new OracleParameter(":CREATE_TIME", OracleType.DateTime),
					new OracleParameter(":CREATOR_ID", OracleType.VarChar,40),
					new OracleParameter(":UPDATE_TIME", OracleType.DateTime),
					new OracleParameter(":UPDATOR_ID", OracleType.VarChar,40),
					new OracleParameter(":PET_OWENER_ID", OracleType.VarChar,40)};
			parameters[0].Value = model.ADDRESS;
			parameters[1].Value = model.BIRTHDAY;
			parameters[2].Value = model.CARD_ID;
			parameters[3].Value = model.CARD_TYPE;
			parameters[4].Value = model.EMAIL;
			parameters[5].Value = model.MOBILE;
			parameters[6].Value = model.NOTE;
			parameters[7].Value = model.ORG_NAME;
			parameters[8].Value = model.PER_NAME;
			parameters[9].Value = model.PHONE;
			parameters[10].Value = model.POST_NUM;
			parameters[11].Value = model.REG_ORG_ID;
			parameters[12].Value = model.SEX;
			parameters[13].Value = model.IS_SMS;
			parameters[14].Value = model.STATE;
			parameters[15].Value = model.TYPE;
			parameters[16].Value = model.IS_EMAIL;
			parameters[17].Value = model.IS_MAIL;
			parameters[18].Value = model.CREATE_TIME;
			parameters[19].Value = model.CREATOR_ID;
			parameters[20].Value = model.UPDATE_TIME;
			parameters[21].Value = model.UPDATOR_ID;
			parameters[22].Value = model.PET_OWENER_ID;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(string PET_OWENER_ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_PET_OWENER ");
			strSql.Append(" where PET_OWENER_ID=:PET_OWENER_ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":PET_OWENER_ID", OracleType.VarChar,40)			};
			parameters[0].Value = PET_OWENER_ID;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string PET_OWENER_IDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_PET_OWENER ");
			strSql.Append(" where PET_OWENER_ID in ("+PET_OWENER_IDlist + ")  ");
			int rows=DbHelperOra.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public ChinaSoft.Model.Model_T_PET_OWENER GetModel(string PET_OWENER_ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select PET_OWENER_ID,ADDRESS,BIRTHDAY,CARD_ID,CARD_TYPE,EMAIL,MOBILE,NOTE,ORG_NAME,PER_NAME,PHONE,POST_NUM,REG_ORG_ID,SEX,IS_SMS,STATE,TYPE,IS_EMAIL,IS_MAIL,CREATE_TIME,CREATOR_ID,UPDATE_TIME,UPDATOR_ID from T_PET_OWENER ");
			strSql.Append(" where PET_OWENER_ID=:PET_OWENER_ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":PET_OWENER_ID", OracleType.VarChar,40)			};
			parameters[0].Value = PET_OWENER_ID;

			ChinaSoft.Model.Model_T_PET_OWENER model=new ChinaSoft.Model.Model_T_PET_OWENER();
			DataSet ds=DbHelperOra.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["PET_OWENER_ID"]!=null && ds.Tables[0].Rows[0]["PET_OWENER_ID"].ToString()!="")
				{
					model.PET_OWENER_ID=ds.Tables[0].Rows[0]["PET_OWENER_ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["ADDRESS"]!=null && ds.Tables[0].Rows[0]["ADDRESS"].ToString()!="")
				{
					model.ADDRESS=ds.Tables[0].Rows[0]["ADDRESS"].ToString();
				}
				if(ds.Tables[0].Rows[0]["BIRTHDAY"]!=null && ds.Tables[0].Rows[0]["BIRTHDAY"].ToString()!="")
				{
					model.BIRTHDAY=DateTime.Parse(ds.Tables[0].Rows[0]["BIRTHDAY"].ToString());
				}
				if(ds.Tables[0].Rows[0]["CARD_ID"]!=null && ds.Tables[0].Rows[0]["CARD_ID"].ToString()!="")
				{
					model.CARD_ID=ds.Tables[0].Rows[0]["CARD_ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["CARD_TYPE"]!=null && ds.Tables[0].Rows[0]["CARD_TYPE"].ToString()!="")
				{
					model.CARD_TYPE=decimal.Parse(ds.Tables[0].Rows[0]["CARD_TYPE"].ToString());
				}
				if(ds.Tables[0].Rows[0]["EMAIL"]!=null && ds.Tables[0].Rows[0]["EMAIL"].ToString()!="")
				{
					model.EMAIL=ds.Tables[0].Rows[0]["EMAIL"].ToString();
				}
				if(ds.Tables[0].Rows[0]["MOBILE"]!=null && ds.Tables[0].Rows[0]["MOBILE"].ToString()!="")
				{
					model.MOBILE=ds.Tables[0].Rows[0]["MOBILE"].ToString();
				}
				if(ds.Tables[0].Rows[0]["NOTE"]!=null && ds.Tables[0].Rows[0]["NOTE"].ToString()!="")
				{
					model.NOTE=ds.Tables[0].Rows[0]["NOTE"].ToString();
				}
				if(ds.Tables[0].Rows[0]["ORG_NAME"]!=null && ds.Tables[0].Rows[0]["ORG_NAME"].ToString()!="")
				{
					model.ORG_NAME=ds.Tables[0].Rows[0]["ORG_NAME"].ToString();
				}
				if(ds.Tables[0].Rows[0]["PER_NAME"]!=null && ds.Tables[0].Rows[0]["PER_NAME"].ToString()!="")
				{
					model.PER_NAME=ds.Tables[0].Rows[0]["PER_NAME"].ToString();
				}
				if(ds.Tables[0].Rows[0]["PHONE"]!=null && ds.Tables[0].Rows[0]["PHONE"].ToString()!="")
				{
					model.PHONE=ds.Tables[0].Rows[0]["PHONE"].ToString();
				}
				if(ds.Tables[0].Rows[0]["POST_NUM"]!=null && ds.Tables[0].Rows[0]["POST_NUM"].ToString()!="")
				{
					model.POST_NUM=ds.Tables[0].Rows[0]["POST_NUM"].ToString();
				}
				if(ds.Tables[0].Rows[0]["REG_ORG_ID"]!=null && ds.Tables[0].Rows[0]["REG_ORG_ID"].ToString()!="")
				{
					model.REG_ORG_ID=ds.Tables[0].Rows[0]["REG_ORG_ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["SEX"]!=null && ds.Tables[0].Rows[0]["SEX"].ToString()!="")
				{
					model.SEX=ds.Tables[0].Rows[0]["SEX"].ToString();
				}
				if(ds.Tables[0].Rows[0]["IS_SMS"]!=null && ds.Tables[0].Rows[0]["IS_SMS"].ToString()!="")
				{
					model.IS_SMS=ds.Tables[0].Rows[0]["IS_SMS"].ToString();
				}
				if(ds.Tables[0].Rows[0]["STATE"]!=null && ds.Tables[0].Rows[0]["STATE"].ToString()!="")
				{
					model.STATE=ds.Tables[0].Rows[0]["STATE"].ToString();
				}
				if(ds.Tables[0].Rows[0]["TYPE"]!=null && ds.Tables[0].Rows[0]["TYPE"].ToString()!="")
				{
					model.TYPE=decimal.Parse(ds.Tables[0].Rows[0]["TYPE"].ToString());
				}
				if(ds.Tables[0].Rows[0]["IS_EMAIL"]!=null && ds.Tables[0].Rows[0]["IS_EMAIL"].ToString()!="")
				{
					model.IS_EMAIL=ds.Tables[0].Rows[0]["IS_EMAIL"].ToString();
				}
				if(ds.Tables[0].Rows[0]["IS_MAIL"]!=null && ds.Tables[0].Rows[0]["IS_MAIL"].ToString()!="")
				{
					model.IS_MAIL=ds.Tables[0].Rows[0]["IS_MAIL"].ToString();
				}
				if(ds.Tables[0].Rows[0]["CREATE_TIME"]!=null && ds.Tables[0].Rows[0]["CREATE_TIME"].ToString()!="")
				{
					model.CREATE_TIME=DateTime.Parse(ds.Tables[0].Rows[0]["CREATE_TIME"].ToString());
				}
				if(ds.Tables[0].Rows[0]["CREATOR_ID"]!=null && ds.Tables[0].Rows[0]["CREATOR_ID"].ToString()!="")
				{
					model.CREATOR_ID=ds.Tables[0].Rows[0]["CREATOR_ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["UPDATE_TIME"]!=null && ds.Tables[0].Rows[0]["UPDATE_TIME"].ToString()!="")
				{
					model.UPDATE_TIME=DateTime.Parse(ds.Tables[0].Rows[0]["UPDATE_TIME"].ToString());
				}
				if(ds.Tables[0].Rows[0]["UPDATOR_ID"]!=null && ds.Tables[0].Rows[0]["UPDATOR_ID"].ToString()!="")
				{
					model.UPDATOR_ID=ds.Tables[0].Rows[0]["UPDATOR_ID"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select PET_OWENER_ID,ADDRESS,BIRTHDAY,CARD_ID,CARD_TYPE,EMAIL,MOBILE,NOTE,ORG_NAME,PER_NAME,PHONE,POST_NUM,REG_ORG_ID,SEX,IS_SMS,STATE,TYPE,IS_EMAIL,IS_MAIL,CREATE_TIME,CREATOR_ID,UPDATE_TIME,UPDATOR_ID ");
			strSql.Append(" FROM T_PET_OWENER ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperOra.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM T_PET_OWENER ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.PET_OWENER_ID desc");
			}
			strSql.Append(")AS Row, T.*  from T_PET_OWENER T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperOra.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			OracleParameter[] parameters = {
					new OracleParameter(":tblName", OracleType.VarChar, 255),
					new OracleParameter(":fldName", OracleType.VarChar, 255),
					new OracleParameter(":PageSize", OracleType.Number),
					new OracleParameter(":PageIndex", OracleType.Number),
					new OracleParameter(":IsReCount", OracleType.Clob),
					new OracleParameter(":OrderType", OracleType.Clob),
					new OracleParameter(":strWhere", OracleType.VarChar,1000),
					};
			parameters[0].Value = "T_PET_OWENER";
			parameters[1].Value = "PET_OWENER_ID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperOra.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

